var app = angular.module('menuApp', []);

$("#status").select2({
	 placeholder: "请选择菜单状态",
	 allowClear: true
});

app.controller('menuController', function($scope, $http, MenuService) {
	$scope.load=function(){
		MenuService.list($scope.sel).success(function (response) {
			$scope.menuList=response.data;
	    });
	}
	
	$scope.load();
    $scope=pagination.init($scope);
    $scope.menuCreator=function(){
    	redirectUrl("manage/menu/","add.jsp");
    }
    $scope.refreshData=function(){
    	$scope.load();
    }
    $scope.lock=function(id){
    	MenuService.lock(id).success(function (response) {
    		$scope.load();
    	});
    }
    $scope.delTip=function(id,mes){
    	$scope.delItem={id:id,mes:mes};
    	$('#box-del').modal({
    		show: true
    	});
    	
    }
    $scope.del=function(id){
    	MenuService.del(id).success(function (response) {
    		$('#box-del').modal('hide');
    		$scope.load();
    	});
    }
});

app.factory('MenuService', function ($http) {
	var list = function (param) {
        return $http({
            params: param,
           // url: 'sys/menus/getAll'
            url: timestamp('sys/menus/getAll')
        });
    };
    var lock = function (id){
    	return $http.put('sys/menus/lock/'+id);
    }
    var del = function (id){
    	return $http.put('sys/menus/del/'+id);
    }
	return {
		list:function(param){
			return list(param);
		},
		lock:function(id){
			return lock(id);
		},
		del:function(id){
			return del(id);
		}
	}
});
